"""
ForgeFed plugin for Pagure.
Copyright (C) 2020-2021 zPlus <zplus@peers.community>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, see <https://www.gnu.org/licenses/>.

SPDX-FileCopyrightText:  2020-2021 zPlus <zplus@peers.community>
SPDX-License-Identifier: GPL-2.0-only
"""

def create_tagref(repository, ref):
    """
    Feed to show when a new Tag has been created on a Git repository.
    """

    return {
        'type': 'create_git_tag',

        'repository': {
            'name': repository['name'],
            'id': repository['id']
        },

        'ref': {
            'name': ref['name'],
            'id': ref['id']
        },
    }

def follow(follower=None, followee=None):
    """
    Feed to show when a Follow request has been sent.

    :param follower: The actor that followed
    :type follower: dict

    :param followee: The actor being followed
    :type followee: dict
    """

    return {
        'type': 'follow',

        'follower': {
            'name': follower['name'],
            'id': follower['id']
        },

        'followee': {
            'name': followee['name'],
            'id': followee['id']
        },
    }

def accept_follow(follower=None, followee=None):
    """
    Feed to show when a Follow request has been accepted.

    :param follower: The actor that sent the Follow Activity
    :type follower: dict

    :param followee: The actor that Accepted the Follow Activity
    :type followee: dict
    """

    return {
        'type': 'accept_follow',

        'follower': {
            'name': follower['name'],
            'id': follower['id']
        },

        'followee': {
            'name': followee['name'],
            'id': followee['id']
        },
    }

def accept_ticket(tickettracker, ticket):
    """
    :param tickettracker: The TicketTracker that accepted the Ticket
    :type follower: dict

    :param followee: The Ticket
    :type followee: dict
    """

    return {
        'type': 'accept_ticket',

        'tickettracker': {
            'name': tickettracker['name'],
            'id': tickettracker['id']
        },

        'ticket': {
            'summary': ticket['summary'],
            'id': ticket['id']
        },
    }

def delete_ticket(actor, ticket):
    """
    :param tickettracker: The TicketTracker that accepted the Ticket
    :type follower: dict

    :param followee: The Ticket
    :type followee: dict
    """

    return {
        'type': 'delete_ticket',

        'actor': {
            'name': actor.username,
            'id': actor.uri
        },

        'ticket': {
            'id': ticket['id']
        },
    }

def accept_mergerequest(mergerequest):
    """
    :param mergerequest: The mergerequest that was accepted
    :type follower: dict
    """

    return {
        'type': 'accept_mergerequest',

        'mergerequest': {
            'summary': mergerequest['summary'],
            'id': mergerequest['id']
        },
    }

